//
//  LBViewController.m
//  LBPopoverView
//
//  Created by LINAICAI on 09/12/2017.
//  Copyright (c) 2017 LINAICAI. All rights reserved.
//

#import "LBViewController.h"
#import "LBPopoverView.h"
#import "LBPopItem.h"
@interface LBViewController ()

@end

@implementation LBViewController
#pragma mark- buttonClickLeft
- (void)buttonClickLeft:(UIBarButtonItem *)sender event:(UIEvent *)event{
    LBPopItem *item1 = [LBPopItem itemWithTitle:@"岗位管理" image:[UIImage imageNamed:@"1.png"] action:^(){
        
    }];
    LBPopItem *item2 = [LBPopItem itemWithTitle:@"简历管理" image:[UIImage imageNamed:@"2.png"] action:^(){
        
    }];
    LBPopItem *item3 = [LBPopItem itemWithTitle:@"面试管理" image:[UIImage imageNamed:@"3.png"] action:^(){
        
    }];
    LBPopItem *item4 = [LBPopItem itemWithTitle:@"寻猎需求管理" image:[UIImage imageNamed:@"4.png"] action:^(){
        
    }];
    LBPopItem *item5 = [LBPopItem itemWithTitle:@"助手服务管理" image:[UIImage imageNamed:@"4.png"] action:^(){
        
    }];
    LBPopItem *item6 = [LBPopItem itemWithTitle:@"会员服务" image:[UIImage imageNamed:@"4.png"] action:^(){
        
    }];
    UIView *view =  [[event.allTouches anyObject] view];
    CGRect rect ;
    if (@available(iOS 11.0, *)) {
        rect =  [view convertRect:view.frame toView:[UIApplication sharedApplication].delegate.window];
    } else {
        rect = view.frame;
    }
    [LBPopoverView showInView:self.view from:rect withItems:@[item1,item2,item3,item4,item5,item6] position:LBPopoverArrowPositionLeft];
}
#pragma mark- buttonClickRight
- (void)buttonClickRight:(UIBarButtonItem *)sender event:(UIEvent *)event{
    LBPopItem *item1 = [LBPopItem itemWithTitle:@"岗位管理" image:[UIImage imageNamed:@"1.png"] action:^(){
        
    }];
    LBPopItem *item2 = [LBPopItem itemWithTitle:@"简历管理" image:[UIImage imageNamed:@"2.png"] action:^(){
        
    }];
    LBPopItem *item3 = [LBPopItem itemWithTitle:@"面试管理" image:[UIImage imageNamed:@"3.png"] action:^(){
        
    }];
    LBPopItem *item4 = [LBPopItem itemWithTitle:@"寻猎需求管理" image:[UIImage imageNamed:@"4.png"] action:^(){
        
    }];
    LBPopItem *item5 = [LBPopItem itemWithTitle:@"助手服务管理" image:[UIImage imageNamed:@"4.png"] action:^(){
        
    }];
    LBPopItem *item6 = [LBPopItem itemWithTitle:@"会员服务" image:[UIImage imageNamed:@"4.png"] action:^(){
        
    }];
    UIView *view =  [[event.allTouches anyObject] view];
    CGRect rect =  [view.superview convertRect:view.frame toView:[UIApplication sharedApplication].delegate.window];
    [LBPopoverView showInView:self.view from:rect withItems:@[item1,item2,item3,item4,item5,item6] position:LBPopoverArrowPositionRight];
}
#pragma mark- buttonClickMiddle
- (void)buttonClickMiddle:(UIBarButtonItem *)sender event:(UIEvent *)event{
    LBPopItem *item1 = [LBPopItem itemWithTitle:@"岗位管理" image:[UIImage imageNamed:@"1.png"] action:^(){
        NSLog(@"岗位管理");
    }];
    LBPopItem *item2 = [LBPopItem itemWithTitle:@"简历管理" image:[UIImage imageNamed:@"2.png"] action:^(){
        NSLog(@"简历管理");
    }];
    LBPopItem *item3 = [LBPopItem itemWithTitle:@"面试管理" image:[UIImage imageNamed:@"3.png"] action:^(){
        NSLog(@"面试管理");
    }];
    LBPopItem *item4 = [LBPopItem itemWithTitle:@"寻猎需求管理" image:[UIImage imageNamed:@"4.png"] action:^(){
        NSLog(@"寻猎需求管理");
    }];
    LBPopItem *item5 = [LBPopItem itemWithTitle:@"助手服务管理" image:[UIImage imageNamed:@"4.png"] action:^(){
        NSLog(@"助手服务管理");
    }];
    LBPopItem *item6 = [LBPopItem itemWithTitle:@"会员服务" image:[UIImage imageNamed:@"4.png"] action:^(){
        NSLog(@"会员服务");
    }];
    UIView *view =  [[event.allTouches anyObject] view];
    CGRect rect =  [view.superview convertRect:view.frame toView:[UIApplication sharedApplication].delegate.window];
    
    [LBPopoverView showInView:self.view from:rect withItems:@[item1,item2,item3,item4,item5,item6] position:LBPopoverArrowPositionMiddle];
}
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
- (void)loadView{
    self.view = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.view.backgroundColor = [UIColor whiteColor];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UIBarButtonItem appearance]setTintColor:[UIColor whiteColor]];
    
    self.navigationItem.rightBarButtonItem =  [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"add.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(buttonClickRight:event:)];
    
    
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"add.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(buttonClickLeft:event:)];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"add.png"] forState:UIControlStateNormal];
    button.frame = CGRectMake(0, 0, 100, 44);
    [button addTarget:self action:@selector(buttonClickMiddle:event:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.titleView = button;
    
    UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [nextButton setTitle:@"Push" forState:UIControlStateNormal];
    nextButton.frame = CGRectMake(0, 0, 100, 44);
    nextButton.center = self.view.center;
    nextButton.layer.borderWidth = 1/[UIScreen mainScreen].scale;
    nextButton.layer.borderColor = [UIColor grayColor].CGColor;
    
    [nextButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [nextButton addTarget:self action:@selector(nextButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:nextButton];
	// Do any additional setup after loading the view, typically from a nib.
}
- (void)nextButton{
    LBViewController *vc = [[LBViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
